using System;
using System.Linq;
using System.Collections.Generic; 

// This file is auto generated and will be overwritten as soon as the template is executed
// Do not modify this file...
	
namespace Bussiness
{   
	public partial class TON_KHORepository
	{
		private IRepository<TON_KHO> _repository {get;set;}
		public IRepository<TON_KHO> Repository
		{
			get { return _repository; }
			set { _repository = value; }
		}
		
		public TON_KHORepository(IRepository<TON_KHO> repository, IUnitOfWork unitOfWork)
    	{
    		Repository = repository;
			Repository.UnitOfWork = unitOfWork; 
    	}
		
		public IQueryable<TON_KHO> All()
		{
			return Repository.All();
		}


      public TON_KHO GetById(System.DateTime Id)
		{
		    try
			{
		         XUAT_NHAPTONEntities context = (XUAT_NHAPTONEntities)Repository.UnitOfWork.Context;
                 return context.TON_KHO.First(dk => dk.NGAYTHANG == Id);			
			 }
			 catch
			 {
			     return null;
			 }

		}

		//Ham them mot doi tuong sau do tra ve doi tuong duoc them do
		 public TON_KHO SaveReturnToObject(TON_KHO obj)
		{
		    try
			{
		         XUAT_NHAPTONEntities context = (XUAT_NHAPTONEntities)Repository.UnitOfWork.Context;

                 context.TON_KHO.AddObject(obj);	

				 context.SaveChanges();		
			 }
			catch(Exception ex) 
            {
                throw new Exception(ex.Message + ex.StackTrace + ex.Source);
			     return null;
			 }

			 return obj;
		}

		public void Add(TON_KHO entity)
		{
			Repository.Add(entity);
		}
		
		public void Delete(TON_KHO entity)
		{
			Repository.Delete(entity);
		}

		public void Save()
		{
			Repository.Save();
		}
	}
}